package com.batsoft.trade.disruptor.opp;

import com.batsoft.trade.disruptor.base.BaseQueueHelper;
import com.batsoft.trade.util.JedisUtil;
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.WaitStrategy;
import com.lmax.disruptor.WorkHandler;

import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/8/27 13:52
 * <p>
 * 定义
 */
public class OppDataEventQueueHelper extends BaseQueueHelper<OppData, OppDataEvent, OppDataEventHandler> {

    private static final int QUEUE_SIZE = 1024;

    private static List<OppDataEventHandler> oppDataEventHandler = new ArrayList<OppDataEventHandler>();

    public OppDataEventQueueHelper(JedisUtil jedisUtil) {
        super();
        // 定义两个消费者
        for (int i = 0; i < 2; i++) {
            oppDataEventHandler.add(new OppDataEventHandler(jedisUtil));
        }
    }


    @Override
    protected int getQueueSize() {
        return QUEUE_SIZE;
    }

    @Override
    protected com.lmax.disruptor.EventFactory eventFactory() {
        return new OppEventFactory();
    }

    @Override
    protected WorkHandler[] getHandler() {
        int size = oppDataEventHandler.size();
        return oppDataEventHandler.toArray(new WorkHandler[size]);
    }

    @Override
    protected WaitStrategy getStrategy() {
        return new BlockingWaitStrategy();
        //return new YieldingWaitStrategy();
    }

}